package com.tesis_2.UI;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

import com.example.tesis_2.R;
import com.tesis_2.BL.BLRestaurants;
import com.tesis_2.DA.DAOUtils;
import com.tesis_2.DA.ImageDownloader;
import com.tesis_2.MO.MORestaurant;



public class UIRestaurantDetailItem  extends Fragment {
	
	private MORestaurant objRest;
	
	public static final String ARG_SECTION_NUMBER = "section_number";
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
             Bundle savedInstanceState) {
		
		// Inflate the layout for this fragment
		View fragmentView	= inflater.inflate(R.layout.activity_restaurant_detail_item, container, false);
		Bundle args = getArguments();
		setObjRest(BLRestaurants.getLsRest().get(args.getInt("nRest")));
		
		((TextView) fragmentView.findViewById(R.id.txvNombre_restaurant_detail_item)).setText(getObjRest().getName());
		((TextView) fragmentView.findViewById(R.id.txvTipoCocina_restaurant_detail_item)).setText(getObjRest().getCuisine());
		((RatingBar) fragmentView.findViewById(R.id.ratingBar1)).setRating(getObjRest().getScore());
		
		
		
		((TextView) fragmentView.findViewById(R.id.txvDescrpcion_restaurant_detail_item)).setText(getObjRest().getDescr());
		((TextView) fragmentView.findViewById(R.id.txvEmailD_restaurant_detail_item)).setText(getObjRest().getEmail());
		((TextView) fragmentView.findViewById(R.id.txvTelefonoD_restaurant_detail_item)).setText(getObjRest().getPhone());
		
		((Button) fragmentView.findViewById(R.id.btnReservar_restaurant_detail_item)).setOnClickListener(
				
				new OnClickListener() {

					@Override
					public void onClick(View arg0) {
						Intent intent = new Intent(getActivity().getApplicationContext(), UIReservar.class);
						intent.putExtra("RestId", objRest.getId());
						startActivity(intent);
						
					}
				}
		
				);
		
		((Button) fragmentView.findViewById(R.id.btnComentarios_restaurant_detail_item)).setOnClickListener(
				
				new OnClickListener() {

					@Override
					public void onClick(View arg0) {
						Intent intent = new Intent(getActivity().getApplicationContext(), UIComentarios.class);
						intent.putExtra("RestId", objRest.getId());
						startActivity(intent);
						
					}
				}
		
				);
		ImageView imageView = (ImageView) fragmentView
				.findViewById(R.id.imgRest_restaurant_detail_item);
		
		ImageDownloader mDownload = new ImageDownloader();
		//mDownload.download(DAOUtils.getServer()+"/assets/restaurants/"+ objRest.getId()  +"/small/" + objRest.getPhoto(), ((ImageView) fragmentView.findViewById(R.id.imgRest_locales_detail_item)));
		mDownload.download(DAOUtils.getServer()+"/assets/restaurants/"+ getObjRest().getId()  +"/small/" + getObjRest().getPhoto(), imageView);
		
		return  fragmentView;
	
	}

	private MORestaurant getObjRest() {
		return objRest;
	}

	private void setObjRest(MORestaurant objRest) {
		this.objRest = objRest;
	}
	
	
	public void Reservar()
	{
		Context context = getActivity().getApplicationContext();
		CharSequence text = objRest.getName();
		int duration = Toast.LENGTH_SHORT;

		Toast toast = Toast.makeText(context, text, duration);
		toast.show();
	}

}
